package cn.com.twoke.application.game.mario.game.system;

import cn.com.twoke.application.game.mario.core.ecs.component.InputComponent;
import cn.com.twoke.application.game.mario.core.ecs.component.InputState;
import cn.com.twoke.application.game.mario.core.ecs.entity.Entity;
import cn.com.twoke.application.game.mario.core.ecs.system.LogicGameSystem;
import cn.com.twoke.application.game.mario.game.component.PlayerControlComponent;

import java.util.List;

/**
 * 玩家控制系统
 */
public class PlayerControlSystem implements LogicGameSystem {

    private final InputState inputState;
    private final Class<? extends InputComponent>[] inputComponentTypes;
    public PlayerControlSystem(InputState inputState) {
        this.inputState = inputState;
        this.inputComponentTypes = new Class[]{
           PlayerControlComponent.class
        };
    }

    @Override
    public void update(List<Entity> entities, double delta) {
        for (Entity entity : entities) {
            for (Class<? extends InputComponent> inputComponentType : this.inputComponentTypes) {
                if (entity.hasComponent(inputComponentType)) {
                    InputComponent input = entity.getComponent(inputComponentType);
                    input.update(entity, inputState, delta);
                }
            }
        }
    }

}
